#ifndef SCHEDULER_H_
#define SCHEDULER_H_

/* INCLUDES *******************************************************************/

#include "ses_common.h"
#include "alarm_clock.h"



/* MACROS AND DEFINES *********************************************************/

#define SCHEDULER_ENTRIES	  20
#define IMMEDIATELY			   0
#define MILLISECOND			   1
#define ONE_SECOND			1000

#define MILLI_REMAINDER 	1000
#define SEC_REMAINDER 		  60
#define MIN_REMAINDER 		  60
#define HOUR_REMAINDER 		  24
#define MILLI_TO_SEC 		1000
#define MILLI_TO_MIN 	   60000
#define MILLI_TO_HOUR 	 3600000
#define SEC_TO_MILLI 		1000
#define MIN_TO_MILLI 	   60000
#define HOUR_TO_MILLI 	 3600000



/* TYPES AND STRUCTS **********************************************************/

typedef void (*task_t)(void);
struct type_timeRTC;



/* FUNCTIONS ******************************************************************/

/*
 * Initializes the task scheduler.
 */
void scheduler_init();

/*
 * Runs scheduler in an infinite loop.
 */
void scheduler_run();

/*
 * Adds new task to the scheduler. A scheduled task is executed once after the
 * given time period.
 *
 * @param task		valid pointer to task
 * @param expire	time period
 */
bool scheduler_add( task_t task, uint16_t expire);

/*
 * Removes a timer task from the scheduler.
 *
 * @param task	pointer to timer
 */
void scheduler_remove(task_t task);

/**
 * Returns clock time in milliseconds.
 */
uint32_t scheduler_getTime();

/**
 * Sets clock time in milliseconds
 */
void scheduler_setTime(uint32_t);

/**
 * Get the current clock time as type_timeRTC object.
 *
 * @param time	object to store the current time
 */
void scheduler_getTimeRTC(struct type_timeRTC *time);

/**
 * Set the current clock time from a type_timeRTC object.
 *
 * @param time	object to get the current time from
 */
void scheduler_setTimeRTC(const struct type_timeRTC *time);



#endif /* SCHEDULER_H_ */
